package hcontroller

import (
	"encoding/json"

	"advertoper/controllers"
	"advertoper/errorcode"
	"advertoper/homepageinfo/hservice"
)

type AdminManageController struct {
	controllers.SCLoginedController
}

//添加总体容器控制
// @router /total-layout/add [post]
func (p *AdminManageController) TotalLayoutAdd() {
	defer p.Output("TotalLayoutAdd")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.TotalLayoutAddReq{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetAdminManageService().TotalLayoutAdd(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
}

//修改总体容器控制
// @router /total-layout/update [post]
func (p *AdminManageController) TotalLayoutUpdate() {
	defer p.Output("TotalLayoutUpdate")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.TotalLayoutUpdateReq{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetAdminManageService().TotalLayoutUpdate(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
}

//显示总体容器控制
// @router /total-layout/list [get]
func (p *AdminManageController) TotalLayoutList() {
	defer p.Output("TotalLayoutList")
	p.ForceHTTPS()

	source, _ := p.GetInt("source", 0)
	code, msg, data := hservice.GetAdminManageService().TotalLayoutList(source)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
	if code == 0 {
		p.Resp["data"] = data
	}
}

//添加容器
// @router /container/add [post]
func (p *AdminManageController) ContainerAdd() {
	defer p.Output("ContainerAdd")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ContainerAddReq{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetAdminManageService().ContainerAdd(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
}

//修改容器
// @router /container/update [post]
func (p *AdminManageController) ContainerUpdate() {
	defer p.Output("ContainerUpdate")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ContainerUpdateReq{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetAdminManageService().ContainerUpdate(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
}

//显示容器列表
// @router /container/list [get]
func (p *AdminManageController) ContainerList() {
	defer p.Output("ContainerList")
	p.ForceHTTPS()

	containerType, _ := p.GetInt("container_type", 0)
	source, _ := p.GetInt("source", 0)
	code, msg, data := hservice.GetAdminManageService().ContainerList(source, containerType)
	p.Resp["code"] = code
	p.Resp["msg"] = msg
	if code == 0 {
		p.Resp["data"] = data
	}
}
